package com.ibeeking.found.report.rest.controller.v1;

import com.ibeeking.found.report.rest.service.IBaseService;
import com.ibeeking.found.report.rest.service.IReportExcelService;
import com.ibeeking.found.report.rest.service.IReportShareService;
import com.ibeeking.found.report.service.common.constant.ResponseCode;
import com.ibeeking.found.report.service.common.dos.ReportExcelDO;
import com.ibeeking.found.report.service.common.param.ReportShareParam;
import com.ibeeking.found.report.service.common.po.ResponseBean;
import com.ibeeking.found.report.service.common.query.ReportExcelPageQuery;
import com.ibeeking.found.report.service.common.vo.ReportExcelVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author chenkening
 * @date 2021/4/13 15:12
 */
@RestController
@RequestMapping("/reportExcel/v1")
public class DmpReportExcelController extends DmpBaseController<ReportExcelPageQuery, ReportExcelDO, ReportExcelVO> {

    @Resource
    private IReportExcelService reportExcelServiceImpl;

    @Resource
    private IReportShareService reportShareServiceImpl;

    @Override
    public IBaseService<ReportExcelPageQuery, ReportExcelDO> getService() {
        return reportExcelServiceImpl;
    }

    @Override
    public ReportExcelDO getEntity() {
        return new ReportExcelDO();
    }

    @Override
    public ReportExcelVO getDTO() {
        return new ReportExcelVO();
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询报表")
    @GetMapping("/detailByReportCode/{reportCode}")
    public ResponseBean detailByReportCode(@PathVariable String reportCode) {
        ReportExcelVO reportExcelDto = reportExcelServiceImpl.detailByReportCode(reportCode);
        return ResponseBean.builder().data(reportExcelDto).build();
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "预览报表")
    @PostMapping("/preview")
    public ResponseBean preview(@RequestBody ReportExcelVO reportExcelDto) {
        ReportExcelVO result = reportExcelServiceImpl.preview(reportExcelDto);
        return ResponseBean.builder().data(result).build();
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "导出报表")
    @PostMapping("/exportExcel")
    public ResponseBean exportExcel(@RequestBody ReportExcelVO reportExcelDto) {

        return ResponseBean.builder().code(ResponseCode.SUCCESS_CODE)
                .data(reportExcelServiceImpl.exportExcel(reportExcelDto))
                .message("导出成功，请稍后在文件管理中查看").build();
    }

//    @PostMapping("/exportPdf")
//    public ResponseBean exportPdf(@RequestBody ReportExcelVO reportExcelDto) {
//        reportExcelService.exportPdf(reportExcelDto);
//        return ResponseBean.builder().code(ResponseCode.SUCCESS_CODE)
//                .build();
//    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "分享报表")
    @PostMapping("/share")
    public ResponseBean share(@Validated @RequestBody ReportShareParam dto) {
        return ResponseBean.builder().data(reportShareServiceImpl.insertShare(dto)).build();
    }
}
